💥 Add method for acquiring details with a type hint#1278
💥 Add method for acquiring details with a type hint#1278tconley1428 wants to merge 7 commits intomainfrom
Conversation
…ty.Info - Replace ApplicationError.details_with_type_hints with get_detail(index, type_hint) - Add TimeoutError.get_heartbeat_detail() with payload-based lazy loading - Add activity.Info.get_heartbeat_detail() with payload-based access - Make heartbeat_details properties that decode payloads on access - Store raw payloads instead of decoded details to support type hints - Update tests to use new get_detail method 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
temporalio/activity.py
Outdated
| _heartbeat_payloads: Sequence[temporalio.api.common.v1.Payload] | ||
| _payload_converter: temporalio.converter.PayloadConverter |
There was a problem hiding this comment.
This is a backwards incompatible change for those using temporalio.testing.ActivityEnvironment, but we may be ok with that
There was a problem hiding this comment.
It seems to be somewhat incompatible in general, but why do you point out ActivityEnvironment in particular?
| raw_heartbeat_payloads: Sequence[temporalio.api.common.v1.Payload] | ||
| payload_converter: temporalio.converter.PayloadConverter |
There was a problem hiding this comment.
IMO (but can be separate PR), we should also expose ActivityEnvironment.default_info() static method and tell people here in API docs that constructing Info is not stable/supported and for testing, they should use dataclasses.replace on ActivityEnvironment.default_info().
| ) | ||
| return self.payload_converter.from_payloads(self.raw_heartbeat_payloads, None) | ||
|
|
||
| def heartbeat_detail(self, index: int = 0, type_hint: type | None = None) -> Any: |
There was a problem hiding this comment.
You probably could make this generic w/ proper return type, and the default type hint arguably should be Any, but not a big deal
| heartbeat_details = ( | ||
| [] | ||
| if not start.heartbeat_details | ||
| else await data_converter.decode(start.heartbeat_details) |
There was a problem hiding this comment.
Where is payload codec occurring? We need to pass in data converter to the activity info probably instead of payload converter
There was a problem hiding this comment.
Good call. Different from the other ones in the workflow.
There was a problem hiding this comment.
Hmmm. But that's async and not available if you call the old synchronous heartbeat_details.
|
Going to table this PR due to compat concerns until we have a user need. |
What was changed
Add methods for acquiring details with a type hint. Affects:
ApplicationErrorTimeoutErroractivity.Info💥 This is a breaking change for users constructing their own
activity.Info. Such users will need to pass encoded details toraw_heartbeat_detailsinstead.Why?
Checklist
Closes [Bug] Add ability to obtain
ApplicationErrordetails with type hint #1262How was this tested: